const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    theme:app.theme,
    active:0,
    tab:[
      {status:1,tabname:'全部'},
      {status:2,tabname:'待付款'},
      {status:3,tabname:'待提货'},
      {status:4,tabname:'已提货'},
      {status:5,tabname:'待评论'},
      {status:6,tabname:'已完成'}
    ],
    status:1,
    list:20,
    imageURL:'http://gw.alicdn.com/bao/upload/TB1TOPeGhD1gK0jSZFyXXciOVXa.jpg_Q75.jpg',
    ProductList:[],
    loading:true,
    isempty:false,
    currPage:1,
    perPage:10,
    NoMore:false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getProductsList();
  },
  onClick(event) {
    let index=event.detail.index;
    this.setData({
      status:this.data.tab[index].status,
      active:index
    })
    app.functions.showToast(index);
  },
  toDelete(){
    wx.showModal({
      title: '温馨提示',
      content: '确定删除该订单!',
      showCancel: true,
      cancelText: '取消',
      cancelColor: '#000000',
      confirmText: '确定',
      confirmColor: '#3CC51F',
      success: (result) => {
        if (result.confirm) {
          
        }
      },
      fail: () => {},
      complete: () => {}
    });
  },
  // 去评论
  toComment(){
    wx.navigateTo({
      url: '/pages_user/comment/comment'
    });
  },
  // 取消订单
  toCancel(){
    wx.showModal({
      title: '温馨提示',
      content: '确定取消该订单!',
      showCancel: true,
      cancelText: '取消',
      cancelColor: '#000000',
      confirmText: '确定',
      confirmColor: '#3CC51F',
      success: (result) => {
        if (result.confirm) {
          
        }
      },
      fail: () => {},
      complete: () => {}
    });
  },
  // 查看订单详情
  toRead(){
    wx.navigateTo({
      url: '/pages_user/order-detail/order-detail'
    });
      
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    let that=this;
    that.data.currPage=1;
    that.setData({
      NoMore:false
    })
    that.getProductsList();
    setTimeout(() => {
      wx.stopPullDownRefresh();
    }, 2000);
  },
  onPageScroll: function(e) {
    let that=this;
    if (e.scrollTop > 200) {
      that.selectComponent("#totop").open();
    } else {
      that.selectComponent("#totop").close();
    }
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let that=this;
    if(that.data.NoMore==true)return;
    that.setData({
      loading:true
    })
    that.data.currPage = parseInt(that.data.currPage) + 1;
    that.getProductsList();
  },
  getProductsList() {
    let that = this;
    that.setData({
      loading:true
    })
    setTimeout(()=>{
      that.setData({
        ProductList:that.data.ProductList.concat(app.data.orderList),
        loading:false
      })
    },2000)
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})